package org.huel.backend.mapper;

import org.apache.ibatis.annotations.*;
import org.huel.backend.domain.entity.AttendanceSummary;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: xuanx
 * \* Date: 2025/6/14
 * \* Time: 13:16
 * \* Description:
 * \
 */
@Mapper
public interface AttendanceSummaryMapper {
    /**
     * 获取最新的出勤汇总记录
     * @return 出勤汇总记录
     */
    @Select("SELECT * FROM attendance_summary ORDER BY last_updated DESC LIMIT 1")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "totalPresent", column = "total_present"),
            @Result(property = "totalAbsent", column = "total_absent"),
            @Result(property = "lastUpdated", column = "last_updated")
    })
    AttendanceSummary selectLatestSummary();

    /**
     * 插入新的出勤汇总记录
     * @param summary 出勤汇总实体
     * @return 影响的行数
     */
    @Insert("INSERT INTO attendance_summary (total_present, total_absent) VALUES (#{totalPresent}, #{totalAbsent})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertSummary(AttendanceSummary summary);

    /**
     * 更新出勤汇总记录
     * @param summary 出勤汇总实体
     * @return 影响的行数
     */
    @Update("UPDATE attendance_summary SET total_present = #{totalPresent}, total_absent = #{totalAbsent} WHERE id = #{id}")
    int updateSummary(AttendanceSummary summary);
}
